package com.hy.mydesktop.client.mvc.util;

import java.util.Map;

import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.component.mvc.factory.GxtComponentControlerFactory;
import com.hy.mydesktop.client.mvc.base.BaseController;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel;


public class ControllerUtil {
	/**
	 * 
	 * <ul>
	 * <li>方法含义：用于判断当前控制器，是否处理该事件</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-10-28；时间：下午上午11:03:29</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param eventStructureMetaModel
	 * @param baseController
	 * @return
	 */
	public static boolean isHandle(EventStructureMetaModel eventStructureMetaModel,BaseController baseController) {
		 
			if (eventStructureMetaModel==null||baseController.getId()==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId().equals(baseController.getId())) {
				return true;
			}
			return false;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：用于判断当前控制器的父控制器，是否接收（处理）该事件</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-11-18；时间：下午上午11:04:30</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param eventStructureMetaModel
	 * @param baseController
	 * @return
	 */
	public static boolean isRootHandle(EventStructureMetaModel eventStructureMetaModel,BaseController baseController) {
		 
		if (eventStructureMetaModel==null||baseController.getId()==null||eventStructureMetaModel.getRootControllerId()==null||eventStructureMetaModel.getRootControllerId().equals(baseController.getId())) {
			return true;
		}
		return false;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：根据元模型（控制器），创建创建控制器，并注册到Dispatcher</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-11-18；时间：下午上午10:59:37</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaModel
	 * @return
	 */
	public static boolean	registerController(GxtComponentControllerMetaModel gxtComponentControllerMetaModel) {
		Dispatcher.get().addController(GxtComponentControlerFactory.createGxtComponentController(gxtComponentControllerMetaModel));
		return true;		
	}
	
	public static void isRenderer(Map<String, Object> map) {
		/*int count = ((Integer) map.get("count") - 1);
		if (count <= 0) {
			Dispatcher.forwardEvent(
					AppEvents.DESKTOP_APPLICATION_RENDER, map);
		} else {
			map.put("count", count);
		}*/
	}
}
